import path from "path"
import { defineConfig, loadEnv } from "vite"
import vue from "@vitejs/plugin-vue"
import vueJsx from "@vitejs/plugin-vue-jsx"
// 为组件里面的script加上name选项
import vueSetupExtend from "vite-plugin-vue-setup-extend"
import VueDevTools from "vite-plugin-vue-devtools"

export default ({ mode }) => {
  const VITE_PORT: number = Number(loadEnv(mode, process.cwd()).VITE_PORT)
  const VITE_OPEN: boolean = loadEnv(mode, process.cwd()).VITE_OPEN === "true" ? true : false
  console.log(VITE_OPEN)
  return defineConfig({
    plugins: [vue(), vueJsx(), vueSetupExtend()],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src")
      }
    },
    server: {
      port: VITE_PORT,
      open: VITE_OPEN
      // proxy: {
      //   "/api": {
      //     target: VITE_APP_SERVER_URL,
      //     changeOrigin: true,
      //     rewrite: (path) => path.replace(/^\/api/, "")
      //   }
      // }
    }
  })
}
